﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Session1
{
    /// <summary>
    /// Interface Design , http://msdn.microsoft.com/en-us/library/ms229022.aspx : AVOID using marker interfaces (interfaces with no members).
    /// FxCop :http://msdn.microsoft.com/en-us/library/ms182128%28VS.80%29.aspx : Avoid empty interfaces
    /// Answer:
    /// http://stackoverflow.com/questions/2086451/compelling-reasons-to-use-marker-interfaces-instead-of-attributes
    /// </summary>
    class Program
    {
        static void Main(string[] args)
        {
            object[] o = new object[2] { new ClassWithAttribute(), new ClassImplementInterface() };

            VerifyAttribute(o);
            VerifyInterface(o);
        }

        private static void VerifyInterface(object[] o)
        {
            foreach (var obj in o)
            {
                if(obj is InterfaceNoData)
                    Console.WriteLine(obj.GetType().FullName + " implement interface");
                else
                    Console.WriteLine(obj.GetType().FullName + " does NOT implement interface");
            }
        }

        private static void VerifyAttribute(object[] o)
        {
            foreach (var obj in o)
            {
                var t = obj.GetType();
                if (t.IsDefined(typeof(MyNoDataAttribute), false))
                    Console.WriteLine(t.FullName + " have attribute");
                else
                    Console.WriteLine(t.FullName + " have NOT attribute");
            }
        }
    }
}
